package com.weizhu.swufer.core.filter;

import com.weizhu.swufer.constant.SwuferConstant;
import com.weizhu.swufer.core.annotation.SwuferFilter;
import com.weizhu.swufer.core.entity.InvokeParam;
import com.weizhu.swufer.core.exception.RpcException;
import com.weizhu.swufer.core.rpc.RpcEngine;

@SwuferFilter(type = SwuferConstant.FILTER_TYPE_PROVIDER,order = -99999)
public class ServerBarrierFilter implements Filter{
    @Override
    public Object doFilter(InvokeParam invokeParam, FilterChain filterChain) throws Exception {

        if (RpcEngine.getInstance().getBarrier().compareAndSet(1,1)){
            throw new RpcException(RpcException.SERVER_SHUTDOWN,
                    "the server is shutdowning,refuse rpc request");
        }
        return filterChain.doFilter(invokeParam);
    }
}
